layui.define(['table', 'form', 'upload', 'admin'], function (exports) {
    var $ = layui.$
        , table = layui.table
        , form = layui.form
        , upload = layui.upload
        , admin = layui.admin;
    //
    table.render({
        elem: '#LAY-user-apply'
        , url: '/admin/user_apply/dataGrids'
        , cols: [[
            {field: 'id', width: 80, title: 'ID', fixed: 'left'},
            {field: 'user_id', width: 150, title: '用户ID'},
            {
                field: 'original_data', width: 200, title: '原始数据'
                , templet: function (d) {
                    if (d.change_type == 3) {
                        d.original_data = parseInt(d.original_data);
                        switch (d.original_data) {
                            case 1:
                                return '用户';
                                break;
                            case 2:
                                return '测试用户';
                                break;
                            case 3:
                                return '主播';
                                break;
                            case 4:
                                return '公司主播';
                                break;
                            case 5:
                                return '测试主播';
                                break;
                        }
                    }
                    return d.original_data;
                }
            },
            {
                field: 'new_data', width: 200, title: '新数据'
                , templet: function (d) {
                    if (d.change_type == 3) {
                        d.new_data = parseInt(d.new_data);
                        switch (d.new_data) {
                            case 1:
                                return '用户';
                                break;
                            case 2:
                                return '测试用户';
                                break;
                            case 3:
                                return '主播';
                                break;
                            case 4:
                                return '公司主播';
                                break;
                            case 5:
                                return '测试主播';
                                break;
                        }
                    }
                    return d.new_data;
                }
            },
            {
                field: 'change_type'
                , width: 100
                , title: '变更类型'
                , templet: function (d) {
                    switch (d.change_type) {
                        case 0:
                            return '用户昵称';
                            break;
                        case 1:
                            return '用户手机号';
                            break;
                        case 2:
                            return '用户头像';
                            break;
                        case 3:
                            return '账号类型';
                            break;
                        default:
                            return "";
                    }
                },
            },
            {
                field: 'change_source'
                , width: 90
                , title: '修改来源'
                , templet: function (d) {
                    // 0  WEB 1 IOS 2 Android.
                    switch (d.change_source) {
                        case 0:
                            return 'WEB';
                        case 1:
                            return 'IOS';
                        case 2:
                            return 'Android';
                        default:
                            return '';
                    }
                },

            },
            {
                field: 'status'
                , width: 80
                , title: '状态'
                , templet: function (d) {
                    // 0 审核中,1 通过 2 驳回
                    switch (d.status) {
                        case 0:
                            return '审核中';
                        case 1:
                            return '通过';
                        case 2:
                            return '驳回';
                        default:
                            return '';
                    }
                },
            },
            {field: 'created_at', width: 180, title: '创建时间',},
            {field: 'updated_at', width: 180, title: '处理时间',},
            {field: 'remark', width: 180, title: '修改备注',},
            {title: '操作', width: 180, align: 'center', fixed: 'right', toolbar: '#table-userlist-operation'}
        ]]
        , page: true
        , limit: 20
        , height: 'full-180'
        , text: '对不起，加载出现异常！'
        , even: true
    });

    //监听工具条
    table.on('tool(LAY-user-apply)', function (obj) {
        if (obj.event == "set_allow") {
            layer.confirm("确定通过该用户的修改吗?", function (index) {
                admin.req({
                    url: "/admin/user_apply/operation",
                    data: {
                        id: obj.data.id,
                        status: 1,
                    },
                    success(res) {
                        if (res.code == 0) {
                            table.reload("LAY-user-apply");
                            layer.msg(res.msg, {icon: 1});
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    },
                });
            });
        } else if (obj.event == "reject") {
            layer.confirm("确定拒绝该用户的修改吗?", function (index) {
                admin.req({
                    url: "/admin/user_apply/operation",
                    data: {id: obj.data.id, status: 2},
                    success(res) {
                        if (res.code == 0) {
                            table.reload("LAY-user-apply");
                            layer.msg(res.msg, {icon: 1});
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    },
                });
            });
        }
    });

    exports('user_apply', {})
});
